<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "xhtml11.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />


<script type="text/javascript" src="highslide/highslide-with-gallery.js"></script>
<link rel="stylesheet" type="text/css" href="highslide/highslide.css" />

<script type="text/javascript">
	hs.graphicsDir = 'highslide/graphics/';
	hs.align = 'center';
	hs.transitions = ['expand', 'crossfade'];
	hs.wrapperClassName = 'dark borderless floating-caption';
	hs.fadeInOut = true;
	hs.dimmingOpacity = .75;
	hs.showCredits = false;

	// Add the controlbar
	if (hs.addSlideshow) hs.addSlideshow({
		//slideshowGroup: 'group1',
		interval: 5000,
		repeat: false,
		useControls: true,
		fixedControls: 'fit',
		overlayOptions: {
			opacity: .6,
			position: 'bottom center',
			hideOnMouseOut: true
		}
	});
</script>

<?php
include 'init.php';
include "./include/membersite_config.php";

if(!$fgmembersite->CheckLogin())
{
    $fgmembersite->RedirectToURL("index.php");
    exit;
}


include 'template/header.php';
?>

<html>

<head>
<title>Search</title>
</head>

<body>

<h3>Search</h3>

<form action="" method="POST">
      <p>
	    <input type="text" name="keywords" /> <input type="submit" value="Search" />
      </p>
</form>	  

<?php
  if (isset($_POST['keywords'])) {
  $suffix = "";
  $keywords = mysql_real_escape_string(htmlentities(trim($_POST['keywords']))); //
  //echo $keywords;
  $errors = array();
  $strongF = "<strong>";
  $strongB = "</strong>";
  
  if (empty($keywords)) {
	$errors[] = 'Please enter a search term';
  } else if (strlen($keywords)<3) {
	$errors[] = 'Your search term must be three or more characters';
  } else if (search_results($keywords) === false) {
	$errors[] = 'You don\'t have any image tagged by '.$strongF.' '.$keywords.' '.$strongB.'';
  }
  
  if (empty($errors)) {
    $results = search_results($keywords);
    $results_num = count($results);
    
    $suffix = ($results_num != 1) ? 's' : ''; 
    
    //echo '<pre>', print_r(search_results($keywords)), '</pre>';
    echo '<p>Your search for <strong>', $keywords, '</strong> returned <strong>', $results_num, '</strong> relative result', $suffix,'.</p>';
    
    foreach($results as $result) {
     
       echo '<a href="uploads/', $result['album'], '/', $result['imageid'], '.', $result['ext'], '" 
	           class="highslide" onclick="return hs.expand(this)">
	         <img src="uploads/thumbs/', $result['album'], '/', $result['imageid'], '.', $result['ext'], '" 
	              alt="Highslide JS" title="Uploaded ', date('D M Y / h:i', $result['timestamp']), '" />
	        </a> [<a href="delete_image?image_id=', $result['id'], '">Delete</a>] 
	         <div class="highslide-caption"> Keywords: &nbsp', $result['keywords'],' </div>';
	     }
    
  
  } else {
    foreach($errors as $error) {
		echo $error, '</br>';
    }
  }
} 
?>

<?php
include 'template/footer.php';
?>	  
</body>
</html>
